package someTestExcemple;

import java.util.Random;
import java.util.Scanner;
import Enum.AirTicketType;


public class test2 {
    public static void main(String[] args) {
        int[] arrs = new int[]{10,20,30};
        //change(arrs);
        System.out.println("main,arrs[1]:"+arrs[1]);
        System.out.println(crateVerificationCode(6));
        int [] arr =arrs.clone();
        arrs[2] =100;
        System.out.println(arr[2]);
        Integer[] a = new Integer[] {11,22,33};
        Integer[] a2 = a.clone();
        a[1] = 666;
        System.out.println(a2[1]);

        //以"--"双引号生成的字符串对象存在字符串常量池中，且相同内容只存储一份
        String str1 ="hhhh";
        String str2 = "hhhh";
        //所以这里为true，地址是一样的，都指向同一个对象
        System.out.println(str1 == str2);
        String str3 = "abc";
        String str4 ="a" + "b" + "c";
        System.out.println(str3 == str4);
    }
    public void demo1() {
        //评委打分案例 输入6名评委的打分，取平均分
        double[] scores = new double[6];
        Scanner sc = new Scanner(System.in);
        double sum = 0;
        for (int i = 0; i < scores.length; i++) {
            System.out.println("请输入"+(i+1)+"评委的打分:");
            scores[i] = sc.nextDouble();
            sum += scores[i];
        }
        System.out.println("该选手总分:");
        System.out.println(String.format("%.4f",sum));
        System.out.println("该选手平均分:");
        System.out.println(String.format("%.4f",sum/scores.length));
    }
    public static void change(int[] arr) {
        //引用类型参数传递案例
        System.out.println("before,change,arrs[1]:"+arr[1]);
        arr[1] =222;
        System.out.println("after,change,arrs[1]:"+arr[1]);
    }

    public static double airTicketPrice(AirTicketType airTicketType,int month) {
        double price = 0;
        switch (airTicketType) {
            case FIRST_CLASS:
                if(month >5 && month <= 10) {
                    price = AirTicketType.FIRST_CLASS.getAirTicketPrice()*0.9;
                } else {
                    price = AirTicketType.FIRST_CLASS.getAirTicketPrice()*0.8;
                }
        }
        return price;
    }
    //生成指定位数的随机验证码
    public static String crateVerificationCode(int n) {
        Random random = new Random();
        StringBuffer code = new StringBuffer();
        for(int i = 0; i < n; i++) {
            //先随机是数字还是大小写字母，在随机值。
            //比如先随机0，1，2分别代表是数字，大写字母，小写字母
            int randomType  = random.nextInt(3); //随机0，1，2的整数
            if(randomType == 0) {
                code.append(random.nextInt(10));
            } else if(randomType == 1) {
                //ASCII中大写字母的ASCII码是65-90，小写字母的ASCII码是97-122
                //数字 '0' 到 '9' 的 ASCII 码值是 48 到 57
                //A-65,a-97 大小写字母的ASCII码相差32 因为其他字符也占了91到96的空间
                code.append((char)(random.nextInt(26)+65));
            } else {
                code.append((char)(random.nextInt(26)+97));
            }

        }
        return code.toString();
    }
}
